package br.com.cefetrn.apoena.view.validator;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import br.com.cefetrn.apoena.dominio.entity.Profissional;
import br.com.nordestefomento.jmatryx.type.A_CadastroDePessoa;

import com.opensymphony.xwork.validator.ValidationException;
import com.opensymphony.xwork.validator.validators.FieldValidatorSupport;

public class Validator4CNPJ extends FieldValidatorSupport {

	private static final Log LOG = LogFactory.getLog(Validator4CNPJ.class);

	public void validate(Object object) throws ValidationException {

		Profissional profissional = (Profissional) getFieldValue(
				"profissional", object);

		if (profissional != null) {

			if (profissional.getCadastro() != null)
				if (!A_CadastroDePessoa.getInstance(profissional.getCadastro())
						.getAutenticadorCP().isValido())
					addFieldError(getFieldName(), object);

		} else
			LOG.warn("profissional == null");

	}
}
